package com.lyb.controller;

import com.lyb.Dto.CategoryDto;
import com.lyb.common.AjaxResult;
import com.lyb.pojo.Category;
import com.lyb.services.impl.CategoryServiceImpl;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/category")
public class CategoryC {
    @Autowired
    CategoryServiceImpl categoryService;
    @PostMapping("/add")
    public AjaxResult add(@RequestBody CategoryDto category){
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        return AjaxResult.success(categoryService.add(category));
    }
    @DeleteMapping("/del")
    public AjaxResult del(Long id){
        categoryService.del(id);
        return AjaxResult.success("操作成功");
    }
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Category category){
        category.setUpdateTime(LocalDateTime.now());
        categoryService.update(category);
        return AjaxResult.success("操作成功");
    }
    @GetMapping("/queryPage")
    public AjaxResult queryPage(Integer pageSize, Integer pageNum){
        return AjaxResult.success(categoryService.queryPage(pageSize,pageNum));
    }

}
